package net.xfok.chemical;

import net.xfok.chemical.common.Constant;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class SearchChemical extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
	private static final String MIMETYPE="text/html";
	private static final String ENCODING="utf-8";
	private WebView wv;
	private ArrayAdapter<String> acate,awx;
	private Spinner scate,swx;
	private Button btSearch,btTx,btFav;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show);
        wv=(WebView)findViewById(R.id.result);
        scate=(Spinner)findViewById(R.id.select_cate);
        swx=(Spinner)findViewById(R.id.select_wx);
        acate=new ArrayAdapter<String>(this,
        		android.R.layout.simple_spinner_item);
        acate.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        awx=new ArrayAdapter<String>(this,
        		android.R.layout.simple_spinner_item);
        awx.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        btSearch=(Button)findViewById(R.id.bt_search);
        btTx=(Button)findViewById(R.id.bt_tx);
        btFav=(Button)findViewById(R.id.bt_fav);
        btSearch.setOnClickListener(this);
        btTx.setOnClickListener(this);
        btFav.setOnClickListener(this);
        setViews();
    }
    
    private void setViews(){
    	for(String cate:Constant.CHEMICAL_TYPES){
    		acate.add(cate);
    	}
    	scate.setAdapter(acate);
    	for(String wx:Constant.CHEMICAL_DANGERS){
    		awx.add(wx);
    	}
    	swx.setAdapter(awx);
    	
    }
    private void loadHtml(){
    	wv.loadData(HTML, MIMETYPE, ENCODING);
        wv.loadDataWithBaseURL(null, HTML, MIMETYPE, ENCODING, null);
    }
    private static String HTML;
    
    static{
    	HTML="<html><head><title>$$$title</title></head>" +
    			"<body><table width=\"100%\" border=\"1\">" +
    			"<tr><td>中文</td><td>化学</td><td>特性</td><td>编码</td></tr>" +
    			"<tr><td>氨</td><td>氨</td><td>1183.h</td><td>1183</td></tr>" +
    			"<tr><td>氨</td><td>氨</td><td>1183.h</td><td>1183</td></tr>" +
    			"</table><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>" +
    			"<br/><br/></body></html>";
    	
    }

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.bt_search:
			loadHtml();
			break;
		case R.id.bt_tx:
			
			break;
		case R.id.bt_fav:
			Intent intent=new Intent(this,Detail.class);
			startActivity(intent);
			break;
		default:
			break;
		}
	}
}